/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","knockout","ojs/ojknockout","promise"],function(a,g){function b(b,c,d){function e(c,f,g,h,k){!c||h.E_(g,f,c)||c.readOnly||(g=k?c.value:d?d(g,f,c,function(b){return a.sf.nM(f,b,c.type)}):a.sf.nM(f,g,c.type),b[f]=g)}this.Yn=function(d){var k=d.properties;if(k){var u=this.Kta=new a.M3(b,c);f.setAttribute=b.setAttribute;f.removeAttribute=b.removeAttribute;b.setAttribute=function(a,b){l(a,b,f.setAttribute,!1)};b.removeAttribute=function(a){l(a,null,f.removeAttribute,!0)};var l=function(c,
d,f,g){c=c.toLowerCase();var h=b.getAttribute(c);f.apply(b,arguments);var n=b.getAttribute(c);n!==h&&(h=a.sf.YX(c),e(k[h],h,n,u,g))};d=Object.keys(k);g=!0;try{d.forEach(function(c){var d=a.sf.eB(c),f=b.hasAttribute(d),g=k[c];f&&(d=b.getAttribute(d),e(g,c,d,u,!1));if(!f||g.readOnly)try{h=!0,b[c]=g.value}finally{h=!1}}),b.classList.add("oj-complete")}finally{g=!1}}return this};this.PJa=function(){return g};this.tZ=function(){return h};this.vO=function(a){this.Kta.vO();var b=Object.keys(f),c;for(c=0;c<
b.length;c++){var d=b[c];a[d]=f[d]}f={}};var f={},g,h}function c(a,b){var c=null,d=a[b];if(null!=d){c=Object.keys(d)[0];d=d[c];if(null==c)throw"Invalid component descriptor key";switch(c){case "inline":c=Promise.resolve(d);break;case "promise":c=d;break;default:throw"Invalid descriptor key "+c+" for the resopurce type: "+b;}}return c}function d(b,c,d){if(null!=b&&(c=a.vg.Xc[c],null!=c&&b&&(c=b[c],"function"===typeof c)))return g.ignoreDependencies(c,b,d)}function e(a,b,c,d){l(c,"properties",function(c,
e){h(a,b,c,e,d)})}function f(a,b,c){l(b,"methods",function(d){var e=b.methods[d].internalName;a[d]=e?c[e].bind(c):c[d].bind(c)})}function h(a,b,c,d,e){function f(b,d){var g=h.peek();g!==b&&(h(b),!e.PJa()||e.tZ())&&(g=new CustomEvent(c+"-changed",{detail:{value:b,previousValue:g,updatedFrom:e.tZ()?"default":d?"external":"internal"}}),a.dispatchEvent(g))}var h=g.observable();k(b,c,function(){return h()},function(a){f(a,!1)});k(a,c,function(){return h.peek()},function(a){if(d.readOnly&&!e.tZ())throw"Read-only property "+
c+" cannot be set";f(a,!0)})}function k(a,b,c,d){Object.defineProperty(a,b,{configurable:!0,enumerable:!0,get:c,set:d})}function l(a,b,c){if(a){var d=a[b]||{};Object.keys(d).forEach(function(a){c(a,d[a])})}}function m(a,b){["methods","properties"].forEach(function(c){l(b,c,function(b){delete a[b]})})}function r(a){var b={};a=a.childNodes;for(var c=0;c<a.length;c++){var d=a[c];if((1===d.nodeType||3===d.nodeType)&&(3!==d.nodeType||d.nodeValue.trim())){var e=d.__oj_slots;(e=null!=e?e:d.getAttribute&&
d.getAttribute("slot"))||(e="");b[e]||(b[e]=[]);b[e].push(d)}}return b}function t(a,b){var c,d=a.childNodes;if(d){c=document.createElement("div");c.setAttribute("data-bind","_ojNodeStorage_");c.style.display="none";b.push(c);for(var e=[],f=0;f<d.length;f++){var g=d[f];1!==g.nodeType&&3!==g.nodeType||e.push(g)}e.forEach(function(a){c.appendChild(a)})}return c}g.bindingHandlers._ojNodeStorage_={init:function(){return{controlsDescendantBindings:!0}}};g.bindingHandlers._ojSlot_={init:function(a,b,c,d,
e){g.utils.domNodeDisposal.addDisposeCallback(a,function(b){if(b=b.__oj_nodestorage)for(var c;c=g.virtualElements.firstChild(a);)null!=c.__oj_slots&&b.appendChild(c)}.bind(null,e));d=e.__oj_slots;b=b();c=g.utils.unwrapObservable;e=c(b.name)||"";var f=c(b.index);if(d=null!=f?[d[e][f]]:d[e]){for(e=0;e<d.length;e++)d[e].__oj_slots=c(b.slot)||"";g.virtualElements.setDomNodeChildren(a,d);return{controlsDescendantBindings:!0}}}};g.virtualElements.allowedBindings._ojSlot_=!0;(function(){a.aR.SX({nodeHasBindings:function(b,
c){return c||1===b.nodeType&&a.vg.$Q(b.nodeName.toLowerCase())},getBindingAccessors:function(b,c,d){if(1===b.nodeType&&(b=b.nodeName.toLowerCase(),a.vg.$Q(b))){d=d||{};if(d.ojComposite)throw"Cannot use ojComposite binding on a custom element whose name is already registered for a composite binding";var e={name:b};d.ojComposite=function(){return e}}return d},preprocessNode:function(b,c){var d;if(1===b.nodeType&&"oj-slot"===b.nodeName.toLowerCase()){d=["name","slot","index"];for(var e="ko _ojSlot_:{",
f=[],g=0;g<d.length;g++){var h=d[g],k;k=b.getAttribute(h);if(null!=k){var l=a.sf.sF(k).expr;null==l&&(l="'"+k+"'");k=l}else k=null;k&&f.push(h+":"+k)}e+=f.join(",");g=document.createComment(e+"}");e=document.createComment("/ko");d=[g];f=b.parentNode;for(f.insertBefore(g,b);0<b.childNodes.length;)g=b.childNodes[0],f.insertBefore(g,b),d.push(g);d.push(e);f.replaceChild(e,b)}return d?d:c}})})();a.vg={};a.vg.Xc={initializeMethod:"initialize",activatedMethod:"activated",attachedMethod:"attached",bindingsAppliedMethod:"bindingsApplied",
disposeMethod:"dispose"};o_("Composite.defaults",a.vg.Xc,a);a.vg.register=function(b,c){b&&(a.vg.dL[b.toLowerCase()]=c)};o_("Composite.register",a.vg.register,a);a.vg.$Q=function(b){return b?a.vg.dL[b.toLowerCase()]:null};a.vg.bpa=function(b,c){if(b){var d=a.vg.dL[b.toLowerCase()];d&&(d._metadata=c)}};a.vg.getMetadata=function(b){return b&&(b=a.vg.dL[b.toLowerCase()])?b._metadata:null};o_("Composite.getMetadata",a.vg.getMetadata,a);a.vg.dL={};g.bindingHandlers.ojComposite={init:function(){return{controlsDescendantBindings:!0}},
update:function(h,k,l,v,w){function y(a){E&&(E.vO(h),E=null);K=a;d(C,"disposeMethod",[h]);C=null;I&&m(h,I);A&&(h.removeChild(A),A=null);I=null;Q={}}function x(a){return function(b){if(K||b!=B)throw z;return a.apply(this,Array.prototype.slice.call(arguments,1))}.bind(null,B)}var z=Error(),C,E,B=-1,K=!1,I,Q={},A,J=g.utils.unwrapObservable;g.ignoreDependencies(function(){g.computed(function(){B++;h.dispatchEvent(new CustomEvent("pending",{bubbles:!0}));y(!1);var l=J(k())||{},l=J(l.name),u=a.vg.$Q(l);
if(!u)throw"Composite is missing a descriptor";var m=c(u,"metadata");a.vg.bpa(l,m);l=null;m?l=m.then(x(function(c){c?(I=c,E=new b(h,w,u.parseFunction),e(h,Q,c,E),E.Yn(c)):(h.classList.add("oj-complete"),a.t.warn("ojComposite is being loaded without metadata. No element properties will be set up"));return Q})):h.classList.add("oj-complete");var v,m=new Promise(function(a){v=a}),Y=q+s++,L={element:h,props:l,slotNodeCounts:m,unique:Y},m=null,S=c(u,"viewModel");S&&(m=S.then(x(function(a){return a="function"===
typeof a?new a(L):d(a,"initializeMethod",[L])||a})));S=null;m&&(S=m.then(x(function(a){return d(a,"activatedMethod",[L])})));var F=c(u,"view");F&&(F=F.then(x(function(a){if("string"===typeof a)a=g.utils.parseHtmlFragment(a);else if(window.DocumentFragment?a instanceof DocumentFragment:a&&11===a.nodeType)a=g.utils.arrayPushAll([],a.childNodes);else if(Array.isArray(a))a=g.utils.arrayPushAll([],a);else throw"The View ("+a+") has an unsupported type";return a})));var R=c(u,"css");R&&(R=R.then(x(function(a){var b=
document.createElement("style");b.type="text/css";b.styleSheet?b.styleSheet.cssText=a:b.appendChild(document.createTextNode(a));document.head.appendChild(b)})));g.applyBindingsToDescendants(w,h);Promise.all([F,m,l,R,S]).then(function(a,b){if(!K&&a==B){var c=b[0];if(!c)throw"ojComposite is missing a View";var e=r(h),k={},n;for(n in e)k[n]=e[n].length;v(k);A=t(h,c);g.virtualElements.setDomNodeChildren(h,c);C=b[1];d(C,"attachedMethod",[L]);c=w.createChildContext(C,void 0,function(a){a.__oj_slots=e;a.__oj_nodestorage=
A;a.$slotNodeCounts=k;a.$props=Q;a.$unique=Y});I&&C&&f(h,I,C);g.applyBindingsToDescendants(c,h);d(C,"bindingsAppliedMethod",[L]);h.dispatchEvent(new CustomEvent("ready",{bubbles:!0}))}}.bind(null,B),function(b,c){c!==z&&null!=c&&a.t.error(c)}.bind(null,B))},null,{disposeWhenNodeIsRemoved:h})});g.utils.domNodeDisposal.addDisposeCallback(h,y.bind(null,!0,w))}};var s=0,q="_ojcomposite"});